package com.linser.gistools.refactoring.javafx.treeitem;

import com.linser.gistools.common.datastore.model.BaseDataStoreModel;
import com.linser.gistools.common.datastore.model.DataTableModel;
import com.linser.gistools.utils.GlobalVariables;
import javafx.scene.Node;
import javafx.scene.control.TreeItem;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;

import java.util.Objects;

/**
 * @author: linser
 * @Desc: 数据库表名类型的 TreeItem
 * @create: 2024-01-26
 */
public class DBTableTreeItem extends TreeItem<String> {
    private DataTableModel dataTableModel;

    public DBTableTreeItem(DataTableModel dataTableModel) {
        super(dataTableModel.getTableName());
        Node itemGrathic = new ImageView(new Image(Objects.requireNonNull(getClass().getResourceAsStream(String.join("", "/", GlobalVariables.mainPackageName, "/image/explorer/table.png")))));
        if(dataTableModel.getIsSpatial()){
            itemGrathic = new ImageView(new Image(Objects.requireNonNull(getClass().getResourceAsStream(String.join("", "/", GlobalVariables.mainPackageName, "/image/explorer/spatialTable.png")))));
        }
        this.setGraphic(itemGrathic);
        this.dataTableModel = dataTableModel;
    }

    public DBTableTreeItem(DataTableModel dataTableModel, final Node graphic) {
        super(dataTableModel.getTableName(),graphic);
        this.dataTableModel = dataTableModel;
    }

    public DBTableTreeItem() {
        super();
    }

    /**
     * Creates a TreeItem with the value property set to the provided object, and
     * the graphic set to the provided Node.
     *
     * @param value The object to be stored as the value of this TreeItem.
     * @param graphic The Node to show in the TreeView next to this TreeItem.
     */
    public DBTableTreeItem(String value, final Node graphic) {
        super(value,graphic);
    }


    public DataTableModel getDataTableModel(){
        return this.dataTableModel;
    }
    public void setDataTableModel(DataTableModel dataTableModel){
        this.dataTableModel = dataTableModel;
    }
}
